package com.springboot.java.design.lru;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Author: TongRui乀
 * @Date: 2020-09-01 14:43
 * @description： 基于LinkedHashMap 实现一个 LRU 缓存
 */
public class LruLinkedHashMap extends LinkedHashMap<String,Object> {

    private int capacity;

    LruLinkedHashMap(int capacity){
        super(capacity, 0.75f, true);
        this.capacity = capacity;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry<String, Object> eldest) {
        if(super.size() > this.capacity){
            return true;
        }
        return false;
    }
}
